package com.ruoyi.web.controller.picture;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.weixin.entity.Fam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.picture.domain.AccountFam;
import com.ruoyi.picture.service.IAccountsFamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家人账单管理Controller
 * 
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/picture/famaccont")
public class AccountFamsController extends BaseController
{
    @Autowired
    private IAccountsFamService accountFamService;

    /**
     * 查询家人账单管理列表
     */
    @PreAuthorize("@ss.hasPermi('picture:famaccont:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountFam accountFam)
    {
        startPage();
        List<AccountFam> list = accountFamService.selectAccountFamList(accountFam);
        List<AccountFam> collect = list.stream().filter(distinctByKey1(s -> s.getId())).collect(Collectors.toList());
//        collect.forEach(System.err::println);
        return getDataTable(collect);
    }
    static <T> Predicate<T> distinctByKey1(Function<? super T, ?> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }

    @GetMapping("/fIdlicst")
    public TableDataInfo fIdlicst( )
    {

        List<Fam> list = accountFamService.fIdlicst( );
        return getDataTable(list);
    }

    /**
     * 导出家人账单管理列表
     */
    @PreAuthorize("@ss.hasPermi('picture:famaccont:export')")
    @Log(title = "家人账单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountFam accountFam)
    {
        List<AccountFam> list = accountFamService.selectAccountFamList(accountFam);
        ExcelUtil<AccountFam> util = new ExcelUtil<AccountFam>(AccountFam.class);
        util.exportExcel(response, list, "家人账单管理数据");
    }

    /**
     * 获取家人账单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('picture:famaccont:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountFamService.selectAccountFamById(id));
    }

    /**
     * 新增家人账单管理
     */
    @PreAuthorize("@ss.hasPermi('picture:famaccont:add')")
    @Log(title = "家人账单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountFam accountFam)
    {
        return toAjax(accountFamService.insertAccountFam(accountFam));
    }

    /**
     * 修改家人账单管理
     */
    @PreAuthorize("@ss.hasPermi('picture:famaccont:edit')")
    @Log(title = "家人账单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountFam accountFam)
    {
        return toAjax(accountFamService.updateAccountFam(accountFam));
    }

    /**
     * 删除家人账单管理
     */
    @PreAuthorize("@ss.hasPermi('picture:famaccont:remove')")
    @Log(title = "家人账单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accountFamService.deleteAccountFamByIds(ids));
    }
}
